package Spil;

import java.awt.Color;
import java.util.*;

import desktop_fields.*;
import desktop_resources.GUI;

public class GameBoard {

	private GameFields[] list = new GameFields[22];

	public GameBoard()
	{
		list[0] = new Startfield(1);
		list[1] = new Territory(700, 3000, "Cold Desert", 2);
		list[2] = new Territory(100, 1000, "Tribe Encampment", 3);
		list[3] = new Territory(1300, 4300, "The Werewall", 4);
		list[4] = new Territory(300, 1500, "Crater", 5);
		list[5] = new Fleet(4000, "Second Sail", 6);
		list[6] = new Territory(500, 2000, "Mountain", 7);
		list[7] = new FieldTax(2000, 0, "Goldmine", 8);
		list[8] = new Territory(1000, 4000, "Black Cave", 9);
		list[9] = new FieldRefuge(5000, "Walled City", 10);
		list[10] = new Territory(1600, 4750, "Mountain Village", 11);
		list[11] = new Fleet(4000, "Sea Grover", 12);
		list[12] = new Territory(2000, 5000, "South Citadel", 13);
		list[13] = new LaborCamp(2500, "Huts in the Mountain", 14);
		list[14] = new Territory(2600, 5500, "Palace Gates", 15);
		list[15] = new FieldTax(4000, 10, "Caravan", 16);
		list[16] = new Fleet(4000, "The Buccaneers", 17);
		list[17] = new LaborCamp(2500, "The Pit", 18);
		list[18] = new Territory(3200, 6000, "Tower", 19);
		list[19] = new FieldRefuge(500, "Monastery", 20);
		list[20] = new Fleet(4000, "Privateer Armade", 21);
		list[21] = new Territory(4000, 8000, "Castle", 22);
	}

	public void randomizer() {
		Collections.shuffle(Arrays.asList(list));
	}
	
	public GameFields getField(int id){
		GameFields field = list[id];
		return field;
	}
	
	public int getStartNumber() {
		String Type = "";
		int i = 0;
		
		while (Type != "Start") {
			GameFields field = getField(i);
			Type = field.getType();
			i++;
		}
		
		return i;
	}

	public void create() {
		Field[] fields = new Field[list.length];

		for (int i = 0; i < list.length; i++) {
			GameFields field = getField(i);
			String Type = field.getType();

			switch (Type) {

			case "Start":
				Startfield start = (Startfield) field;
				fields[i] = new Start.Builder()
				.setTitle(start.getName())
				.setDescription("")
				.setSubText("")
				.setBgColor(Color.WHITE)
				.build();
				break;

			case "Territory":
				Territory territory = (Territory) field;
				fields[i] = new Street.Builder()
				.setTitle(territory.getName())
				.setDescription(Txt.Rent + territory.getRent())
				.setSubText(Txt.Price + territory.getPrice())
				.setBgColor(new Color(147,159,80))
				.build();
				break;

			case "Fleet":
				Fleet fleet = (Fleet) field;
				fields[i] = new Street.Builder()
				.setTitle(fleet.getName())
				.setDescription(Txt.Rent + Txt.Fleet)
				.setSubText(Txt.Price + fleet.getPrice())
				.setBgColor(new Color(7,140,255))
				.build();
				break;

			case "Refuge":
				FieldRefuge refuge = (FieldRefuge) field;
				fields[i] = new Street.Builder()
				.setTitle(refuge.getName())
				.setDescription(Txt.Bonus + refuge.getBonus())
				.setSubText("")
				.setBgColor(new Color(255,153,47))
				.build();
				break;

			case "LaborCamp":
				LaborCamp lc = (LaborCamp) field;
				fields[i] = new Street.Builder()
				.setTitle(lc.getName())
				.setDescription(Txt.Rent + Txt.LaborCamp)
				.setSubText(Txt.Price + lc.getPrice())
				.setBgColor(new Color(255,0,0))
				.build();
				break;

			case "Tax":
				FieldTax tax = (FieldTax) field;
				if (tax.getTaxRate() == 0) {
					fields[i] = new Street.Builder()
					.setTitle(tax.getName())
					.setDescription(Txt.Pay + tax.getTaxAmount())
					.setSubText("")
					.setBgColor(new Color(255,255,0))
					.build();
				}
				else {
					fields[i] = new Street.Builder()
					.setTitle(tax.getName())
					.setDescription(Txt.Pay + tax.getTaxAmount() + Txt.Pay2 + tax.getTaxRatePro() + Txt.Pay3)
					.setSubText("")
					.setBgColor(new Color(255,255,0))
					.build();
				}
				break;

			}
		}

		GUI.create(fields);
	}

	public String toString() {
		String s = "";
		for (int i = 0; i < list.length; i++) {
			s = s + list[i].getName() + "\n";
		}
		return s;
	}
	

}
